/**
 * 
 */
package de.digisalt.dsnesds.editors.projectmeta.model;

/**
 * @author flo
 */
@SuppressWarnings("unused")
public class Model extends AbstractModelBean
{
	// TODO: implement undo/redo --> that's what the variable_orig values are
	// there for.
	/**
	 * the game longname (up to 20 chars)
	 */
	private String	gameName;
	private String	gameName_orig;
	/**
	 * the game shortname (up to 4 chars)
	 */
	private String	shortName;
	private String	shortName_orig;
	/**
	 * rom timing (fastrom/slowrom)
	 */
	private String	timing;
	private String	timing_orig;
	/**
	 * rom addressing (hirom, lorom, exhirom)
	 */
	private String	addressing;
	private String	addressing_orig;
	/**
	 * carttype (ram, rom, special chips, etc.)
	 */
	private String	carttype;
	private String	carttype_orig;
	/**
	 * romsize ... what else to mention here?
	 */
	private String	romsize;
	private String	romsize_orig;
	/**
	 * ramsize ... what else to mention here?
	 */
	private String	ramsize;
	private String	ramsize_orig;
	/**
	 * country to license for
	 */
	private String	country;
	private String	country_orig;
	/**
	 * the licensee publishing the game
	 */
	private String	licensee;
	private String	licensee_orig;
	/**
	 * video format (PAL/NTSC)
	 */
	private String	video;
	private String	video_orig;
	/**
	 * game version (0...255)
	 */
	private int			version;
	private int			version_orig;

	/**
	 * flag indicating dirty state (to speed up dirty indication so that not every
	 * value has to be checked each time
	 */
	private boolean	dirty	= false;

	public Model(String gameName, String shortName, String timing,
			String addressing, String carttype, String romsize, String ramsize,
			String country, String licensee, String video, int version)
	{
		this.gameName = gameName;
		this.shortName = shortName;
		this.timing = timing;
		this.addressing = addressing;
		this.carttype = carttype;
		this.romsize = romsize;
		this.ramsize = ramsize;
		this.country = country;
		this.licensee = licensee;
		this.video = video;
		this.version = version;
		storeAllCurrentValuesAsOriginals();
	}

	/**
	 * this method will put all variable values into the corresponding _orig
	 * variables. This should be done upon model creation and once everything was
	 * saved successfully.
	 */
	private void storeAllCurrentValuesAsOriginals()
	{
		this.gameName_orig = gameName;
		this.shortName_orig = shortName;
		this.timing_orig = timing;
		this.addressing_orig = addressing;
		this.carttype_orig = carttype;
		this.romsize_orig = romsize;
		this.ramsize_orig = ramsize;
		this.country_orig = country;
		this.licensee_orig = licensee;
		this.video_orig = video;
		this.version_orig = version;
		dirty = false;
	}

	/**
	 * @return the gameName
	 */
	public String getGameName()
	{
		return this.gameName;
	}

	/**
	 * @return the shortName
	 */
	public String getShortName()
	{
		return this.shortName;
	}

	/**
	 * @return the timing
	 */
	public String getTiming()
	{
		return this.timing;
	}

	/**
	 * @return the carttype
	 */
	public String getCarttype()
	{
		return this.carttype;
	}

	/**
	 * @return the romsize
	 */
	public String getRomsize()
	{
		return this.romsize;
	}

	/**
	 * @return the addressing
	 */
	public String getAddressing()
	{
		return this.addressing;
	}

	/**
	 * @return the ramsize
	 */
	public String getRamsize()
	{
		return this.ramsize;
	}

	/**
	 * @return the country
	 */
	public String getCountry()
	{
		return this.country;
	}

	/**
	 * @return the licensee
	 */
	public String getLicensee()
	{
		return this.licensee;
	}

	/**
	 * @return the video
	 */
	public String getVideo()
	{
		return this.video;
	}

	/**
	 * @return the version
	 */
	public int getVersion()
	{
		return this.version;
	}

	/**
	 * @param gameName
	 *          the gameName to set
	 */
	public void setGameName(final String gameName)
	{
		if (!this.gameName.equals(gameName))
		{
			this.gameName = gameName;
			this.dirty = true;
		}

	}

	/**
	 * @param shortName
	 *          the shortName to set
	 */
	public void setShortName(final String shortName)
	{
		if (!this.shortName.equals(shortName))
		{
			this.shortName = shortName;
			this.dirty = true;
		}
	}

	/**
	 * @param timing
	 *          the timing to set
	 */
	public void setTiming(final String timing)
	{
		if (!this.timing.equals(timing))
		{
			this.timing = timing;
			this.dirty = true;
		}
	}

	/**
	 * @param carttype
	 *          the carttype to set
	 */
	public void setCarttype(final String carttype)
	{
		if (!this.carttype.equals(carttype))
		{
			this.carttype = carttype;
			this.dirty = true;
		}
	}

	/**
	 * @param romsize
	 *          the romsize to set
	 */
	public void setRomsize(final String romsize)
	{
		if (!this.romsize.equals(romsize))
		{
			this.romsize = romsize;
			this.dirty = true;
		}
	}

	/**
	 * @param addressing
	 *          the addressing to set
	 */
	public void setAddressing(final String addressing)
	{
		if (!this.addressing.equals(addressing))
		{
			this.addressing = addressing;
			this.dirty = true;
		}
	}

	/**
	 * @param ramsize
	 *          the ramsize to set
	 */
	public void setRamsize(final String ramsize)
	{
		if (!this.ramsize.equals(ramsize))
		{
			this.ramsize = ramsize;
			this.dirty = true;
		}
	}

	/**
	 * @param country
	 *          the country to set
	 */
	public void setCountry(final String country)
	{
		if (!this.country.equals(country))
		{
			this.country = country;
			this.dirty = true;
		}
	}

	/**
	 * @param licensee
	 *          the licensee to set
	 */
	public void setLicensee(final String licensee)
	{
		if (!this.licensee.equals(licensee))
		{
			this.licensee = licensee;
			this.dirty = true;
		}
	}

	/**
	 * @param video
	 *          the video to set
	 */
	public void setVideo(final String video)
	{
		if (!this.video.equals(video))
		{
			this.video = video;
			this.dirty = true;
		}
	}

	/**
	 * @param version
	 *          the version to set
	 */
	public void setVersion(final int version)
	{
		changeSupport.firePropertyChange("version", new Integer(this.version),
				new Integer(version));
		if (this.version != version)
		{
			this.version = version;
			this.dirty = true;
		}
	}

	public boolean isDirty()
	{
		return dirty;
	}

	public void modelWasSavedSuccessfully()
	{
		storeAllCurrentValuesAsOriginals();
	}
}
